Skip to content

perf(bdk): batch and harden wallet sync tx lookups#60

Merged
dolcalmi merged 8 commits intomainfrom
perf/bdk-tx-lookup-batching
Apr 18, 2026
Merged

perf(bdk): batch and harden wallet sync tx lookups#60
dolcalmi merged 8 commits intomainfrom
perf/bdk-tx-lookup-batching

Conversation

@dolcalmi
Copy link
Copy Markdown

Summary

  • batch wallet-sync transaction lookups and add conditional raw-tx prewarm for larger wallets to reduce bdk.db.get_tx database pressure
  • replace single-row tx lookup fallback with targeted find_by_ids batching and preserve retryability for unresolved same-sync misses
  • harden forced lookup and miss-resolution semantics so the requested txid is always included and repeated miss_cache lookups can retry safely within the same sync

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes BDK wallet sync transaction lookup behavior by batching DB lookups/miss resolution and optionally prewarming raw transaction cache for large wallets, aiming to reduce bdk.db.get_tx pressure and improve same-sync retry semantics.

Changes:

  • Add a large-wallet gate to prewarm raw-tx cache before sync (based on DB tx count).
  • Replace single-tx fallback lookups with batched find_by_ids and add explicit pending “lookup” vs “miss” queues.
  • Harden pending-drain behavior to guarantee the requested txid is included, and allow safe requeue/retry within the same sync.

Reviewed changes

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/wallet/keychain/wallet.rs Adds pre-sync tx-count check and conditional raw-tx prewarm; includes unit test for threshold gating.
src/bdk/pg/transactions.rs Adds count_active() query and removes single-row find_by_id in favor of batching.
src/bdk/pg/mod.rs Exposes tx_count() and prewarm_raw_txs() on SqlxWalletDb; updates tests to use extend_txs.
src/bdk/pg/lookups.rs Refactors tx lookup/miss resolution into distinct batched paths with forced inclusion and requeue semantics; adds unit test for unresolved filtering.
src/bdk/pg/db_traits.rs Updates tests to use extend_txs.
src/bdk/pg/cache.rs Introduces pending_tx_lookups queue and related drain/requeue helpers; splits “record missing” vs “enqueue miss”.
.sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json Adds SQLX offline metadata for COUNT(*) tx count query.
.sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json Removes SQLX offline metadata for the deleted find_by_id query.
Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/lookups.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/lookups.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/lookups.rs
Comment thread src/wallet/keychain/wallet.rs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/cache.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 1 comment.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/mod.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/bdk/pg/lookups.rs
Comment thread src/bdk/pg/lookups.rs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.

Files not reviewed (2)
  • .sqlx/query-5256bb536a5c8b3421a642b8e4eb005975efe12df569e823b49bbd7b2688d52b.json: Language not supported
  • .sqlx/query-c3fc3bf10aaefb6411ef73538d7a581cde4aee4a44070b237493999ab7d52c2f.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dolcalmi dolcalmi merged commit a8dcfa7 into main Apr 18, 2026
9 checks passed
@dolcalmi dolcalmi deleted the perf/bdk-tx-lookup-batching branch April 18, 2026 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants